<template>
  <div class="signin">
    <my-title title="优点达咨询"></my-title>
    <my-up-form @onSubmit="onSubmit"></my-up-form>
  </div>
</template>

<script>
import MyTitle from '@/components/title.vue'
import MyUpForm from '@/components/UpForm.vue'
import { mapActions } from 'vuex'
import { ActionsSignIn, ActionsGetIndexData } from '@/store/actions-type'
export default {
  name: 'signin',
  methods: {
    async onSubmit(value) {
      try {
        await this[ActionsSignIn](value)
        await this[ActionsGetIndexData]()
        this.signInSuccess('登录成功')
      } catch (error) {
        this.signInFail('登录失败')
      }
    },
    signInSuccess(message) {
      this.$toast.success(message)
      const back = this.back
      if (back) {
        this.$router.push({ path: back })
      } else {
        this.$router.push('/layout')
      }
    },
    signInFail(message) {
      this.$toast.fail(message)
    },
    ...mapActions('user', [ActionsSignIn]),
    ...mapActions('home', [ActionsGetIndexData])
  },
  computed: {
    back() {
      return this.$route.query.back
    }
  },
  components: {
    MyTitle,
    MyUpForm
  }
}
</script>

<style lang="less" scoped></style>
